<?php
class xq_string
{
	function ismp($str)
	{
		if (!isset($str))
		{
			return "";
		}
		if (trim($str) == "")
		{
			return "";
		}
		return $str;
	}
	function Ismp($str)
	{
		if (!isset($str))
		{
			return "";
		}
		if (trim($str) == "")
		{
			return "";
		}
		return $str;
	}
	function formatdatetime($timegeshi,$timestr)
	{
		if($timestr=="")
		{
			return "";
		}
		// echo date("Y-m-d", strtotime(date("Y-m-d H:i:s")));
		return   date($timegeshi, strtotime($timestr));
	}
	function rehtml($str)//去除html代码
	{
		$pattern=array ("'<script[^>]*?>.*?</script>'si", "'<style[^>]*?>.*?</style>'si",  "'<[\/\!]*?[^<>]*?>'si",  "'([\r\n])[\s]+'",  "'&(quot|#34);'i",  "'&(amp|#38);'i",  "'&(lt|#60);'i",  "'&(gt|#62);'i",  "'&(nbsp|#160);'i",  "'&(iexcl|#161);'i",  "'&(cent|#162);'i",  "'&(pound|#163);'i",  "'&(copy|#169);'i",  "'&#(\d+);'e");
		$replace=array ("", "", "\\1", "", "&", "<", ">", " ", chr(161), chr(162), chr(163), chr(169), "chr(\\1)");
		return preg_replace ($pattern, $replace, $str);
	}
	//判断是否数字
	function isnum($str)
	{
		if(ereg("^[0-9]+$",$str))
		{
			return  true;
		}
		return false;
	}
	function sethistory($str,$len=10)
	{
		if(!is_array($_SESSION["pro_history"]))
		{
			$k=array();
			$_SESSION["pro_history"]=$k;
			if($this->Ismp($_COOKIE["pro_his"])!="")
			{
				$hst=split(",",$_COOKIE["pro_his"]);
				$ik=0;
				foreach($hst as $hstx)
				{
					$_SESSION["pro_history"][$ik]=$hstx;
					$ik=$ik+1;
				}
			}
		}
		$ml=0;
		for($i=0;$i<count($_SESSION["pro_history"]);$i++)
		{
			if($_SESSION["pro_history"][$i]==$str)
			{
				unset($_SESSION["pro_history"][$i]);
				$ml=0;
			}
		}
		$_SESSION["pro_history"]=array_values($_SESSION["pro_history"]);
		if($ml==0)
		{
			if(count($_SESSION["pro_history"])>=$len)
			{
				array_pop($_SESSION["pro_history"]);
			}
			array_unshift($_SESSION["pro_history"],$str);
		}
		//$this->uniqueArray($_SESSION["pro_history"]);

	}
	function uniqueArray($array)

	{

		// Get unique elts as keys in assoc. array

		for ($i=0,$n=count($array, 1);$i<$n;$i++)

		$u_array[$array[$i]] = 1;

		// Copy keys only into another array

		reset($u_array, 1);

		for ($i=0,$n=count($u_array, 1);$i<$n;$i++) {

			$unduplicated_array[] = key($u_array, 1);

			next($u_array, 1);

		}

		return $unduplicated_array;

	}
	
}
?>